//
//  IconmasterHttp.m
//  IconMaster
//
//  Created by mac on 2017/8/3.
//  Copyright © 2017年 yangweiwei. All rights reserved.
//

#import "IconmasterHttp.h"
#import "AFNetworking.h"
@implementation IconmasterHttp
+(void) GreatNetWorkingRequestType:(GreatRequestType )requestType andurl:(NSString *)urlString andparameters:(NSDictionary *)dict andcomplete:(complete)complete{
    
    NSString *url_String = [NSString stringWithFormat:@"%@%@",BaseURL, urlString];
    NSLog(@"%@", url_String);
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager setResponseSerializer:[AFHTTPResponseSerializer serializer]];
    if (requestType) {
        [manager POST:url_String parameters:dict progress:^(NSProgress * _Nonnull downloadProgress) {
            //打印下下载进度
//            NSLog(@"%lf",1.0 * downloadProgress.completedUnitCount / downloadProgress.totalUnitCount);
            
        }success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            if (complete) {
            complete(dic,nil);
            }
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
              complete(error, nil);
        }];
    } else {
        [manager GET:url_String parameters:dict progress:^(NSProgress * _Nonnull downloadProgress) {
            //打印下下载进度
//            NSLog(@"%lf",1.0 * downloadProgress.completedUnitCount / downloadProgress.totalUnitCount);
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            if (complete) {
                complete(dic,nil);
            }

        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            complete(error, nil);
        }];
    }
}
@end
